package cn.edu.sdjzu.xg.eagle.mapper;

import cn.edu.sdjzu.xg.eagle.entities.Announcement;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnnouncementMapper {

    @Insert("INSERT INTO Announcement (TeacherID, AdminID, Title, Content, AnnouncementType, ReleaseTime) " +
            "VALUES (#{teacherId}, #{adminId}, #{title}, #{content}, #{announcementType}, #{releaseTime})")
    @Options(useGeneratedKeys = true, keyProperty = "announcementId")
    boolean addAnnouncement(Announcement announcement);

    @Delete("DELETE FROM Announcement WHERE AnnouncementID = #{announcementId}")
    boolean deleteAnnouncement(Integer announcementId);

    @Update("UPDATE Announcement " +
            "SET TeacherID = #{teacherId}, AdminID = #{adminId}, " +
            "Title = #{title}, Content = #{content}, " +
            "AnnouncementType = #{announcementType}, ReleaseTime = #{releaseTime} " +
            "WHERE AnnouncementID = #{announcementId}")
    boolean updateAnnouncement(Announcement announcement);

    @Select("SELECT * FROM Announcement WHERE AnnouncementID = #{announcementId}")
    Announcement findAnnouncementById(Integer announcementId);

    @Select("SELECT * FROM Announcement ORDER BY ReleaseTime DESC")
    List<Announcement> findAllAnnouncements();

    @Select("SELECT * FROM Announcement WHERE TeacherID = #{teacherId} ORDER BY ReleaseTime DESC")
    List<Announcement> findAnnouncementsByTeacherId(Integer teacherId);

    @Select("SELECT * FROM Announcement WHERE AdminID = #{adminId} ORDER BY ReleaseTime DESC")
    List<Announcement> findAnnouncementsByAdminId(Integer adminId);
}